{$CLEO .qa}
{$USE CLEO+}
{$USE Audio}
{$USE newOpcodes}
{$USE ini}

0000: NOP

script_name "TOURQA"

// By ArtemQa146

const
    tour_man = 31@
    obj_1 = 30@
    select = 29@
    render_obj = 25@
    time_out = 27@
    render_model = 26@
    progress = 28@
    coords_x = 24@
    coords_y = 23@
    coords_z = 22@
    angle_1 = 21@
    obj_2 = 20@
    fire_fx = 19@
    tour_man_2 = 18@
    music = 17@
    render_obj_2 = 16@
    left = 1
    right = 2
end

0087: coords_x = 0@ // (float)
0087: coords_y = 1@ // (float)
0087: coords_z = 2@ // (float)
0087: angle_1 = 3@ // (float)
0085: render_model = 4@ // (int)

if
    0E4D: random_percent 5@
then
else
    repeat
    wait 0
    until not locate_char_distance_to_coordinates $PLAYER_ACTOR pos coords_x coords_y coords_z radius 150.0
    0A93: terminate_this_custom_script
end


        repeat
        wait 0
        04ED: load_animation  "PedEventsMod"
        until 04EE:   animation "PedEventsMod" loaded

        
        0E40: get_current_hour 1@
        if or
            1@ >= 21
            1@ < 6
        then
            0209: select = random_int_in_ranges 4 6
        else
            0209: select = random_int_in_ranges 1 4
        end

        model.Load(26)
        model.Load(1463)
        model.Load(367)
        if
            not model.Available(26)
        then
            repeat
            wait 0
            model.Load(26)
            until model.Available(26)
        end
        if
            not model.Available(1463)
        then
            repeat
            wait 0
            model.Load(1463)
            until model.Available(1463)
        end
        if
            not model.Available(367)
        then
            repeat
            wait 0
            model.Load(367)
            until model.Available(367)
        end
        038B: load_requested_models

        009A: tour_man = create_actor_pedtype 21 model 26 at coords_x coords_y coords_z
        0173: set_actor tour_man Z_angle_to angle_1
        0E24: fix_char tour_man ground 1 brightness 1 and_fade_in 0
        
        fire_fx = -1
        
        if
            select == 1
        then

            04C4: store_coords_to 1@ 2@ 3@ from_actor tour_man with_offset 0.0 -0.9 -0.8
            0E01: create_object_no_save 1463 at 1@ 2@ 3@ offset 0 ground 0 to obj_1
            0177: set_object obj_1 Z_angle_to angle_1
            08D2: object obj_1 scale_model 1.0
            07F7: set_object obj_1 destructible 0

            0812: AS_actor tour_man perform_animation "tour_sit" IFP "PedEventsMod" framedelta 4.0 loopA 1 lockX 0 lockY 0 lockF 0 time -1  // versionB
        end
        
        if
            select == 2
        then
            0F02: create_render_object_to_char_bone_from_special tour_man special_model render_model bone 34 offset 0.38 0.17 0 rotation 0 180.0 310.0 store_to render_obj
            0812: AS_actor tour_man perform_animation "tour_map" IFP "PedEventsMod" framedelta 4.0 loopA 1 lockX 1 lockY 1 lockF 0 time -1  // versionB
        end
        
        if
            select == 3
        then
            01B2: give_actor tour_man weapon 43 ammo 60 // Load the weapon model before using this
            0812: AS_actor tour_man perform_animation "tour_cum" IFP "PedEventsMod" framedelta 4.0 loopA 1 lockX 1 lockY 1 lockF 0 time -1  // versionB
        end
        
        if
            select == 4
        then

            04C4: store_coords_to 1@ 2@ 3@ from_actor tour_man with_offset 0.0 -0.9 -0.8
            0E01: create_object_no_save 1463 at 1@ 2@ 3@ offset 0 ground 0 to obj_1
            0177: set_object obj_1 Z_angle_to angle_1
            08D2: object obj_1 scale_model 1.0
            07F7: set_object obj_1 destructible 0

            04C4: store_coords_to 1@ 2@ 3@ from_actor tour_man with_offset 0.0 2.0 -0.8
            0E01: create_object_no_save 1463 at 1@ 2@ 3@ offset 0 ground 1 to obj_2
            angle_1 += 90.0
            0177: set_object obj_2 Z_angle_to angle_1
            08D2: object obj_2 scale_model 0.5
            07F7: set_object obj_2 destructible 0
            
            0400: store_coords_to 1@ 2@ 3@ from_object obj_2 with_offset 0.0 2.0 0.0
            009A: tour_man_2 = create_actor_pedtype 21 model 26 at 1@ 2@ 3@
            angle_1 += 180.0
            0173: set_actor tour_man_2 Z_angle_to angle_1
            0E24: fix_char tour_man_2 ground 1 brightness 1 and_fade_in 0
            
            066D: fire_fx = attach_particle "fire" to_object obj_2 with_offset 0.0 0.0 0.0 type 1
            064C: make_particle fire_fx visible

            0812: AS_actor tour_man perform_animation "tour_sit" IFP "PedEventsMod" framedelta 4.0 loopA 1 lockX 0 lockY 0 lockF 0 time -1  // versionB
            0812: AS_actor tour_man_2 perform_animation "sg1" IFP "PedEventsMod" framedelta 4.0 loopA 1 lockX 0 lockY 0 lockF 0 time -1  // versionB
            
            0AC1: music = load_audio_stream_with_3d_support "SQ/g1.mp3" // IF and SET
            0AC4: link_3d_audio_stream music to_actor tour_man_2
            0AAD: set_audio_stream music state 1
            0AC0: audio_stream music looped 1
            
            0AF0: 1@ = read_int_from_ini_file "cleo\streetmus.ini" section "Models" key "guitar2"
            0F02: create_render_object_to_char_bone_from_special tour_man_2 special_model 1@ bone 24 offset 0 0 0 rotation 0 0 0 store_to render_obj_2
        end
        
        if
            select == 5
        then

            04C4: store_coords_to 1@ 2@ 3@ from_actor tour_man with_offset 0.0 -0.9 -0.8
            0E01: create_object_no_save 1463 at 1@ 2@ 3@ offset 0 ground 0 to obj_1
            0177: set_object obj_1 Z_angle_to angle_1
            08D2: object obj_1 scale_model 1.0
            07F7: set_object obj_1 destructible 0

            04C4: store_coords_to 1@ 2@ 3@ from_actor tour_man with_offset 0.0 2.0 -0.8
            0E01: create_object_no_save 1463 at 1@ 2@ 3@ offset 0 ground 1 to obj_2
            angle_1 += 90.0
            0177: set_object obj_2 Z_angle_to angle_1
            08D2: object obj_2 scale_model 0.5
            07F7: set_object obj_2 destructible 0

            0400: store_coords_to 1@ 2@ 3@ from_object obj_2 with_offset 0.0 -1.4 0.0
            009A: tour_man_2 = create_actor_pedtype 21 model 26 at 1@ 2@ 3@
            0173: set_actor tour_man_2 Z_angle_to angle_1
            0E24: fix_char tour_man_2 ground 1 brightness 1 and_fade_in 0

            066D: fire_fx = attach_particle "fire" to_object obj_2 with_offset 0.0 0.0 0.0 type 1
            064C: make_particle fire_fx visible

            0812: AS_actor tour_man perform_animation "tour_sit" IFP "PedEventsMod" framedelta 4.0 loopA 1 lockX 0 lockY 0 lockF 0 time -1  // versionB
            0812: AS_actor tour_man_2 perform_animation "tour_hand" IFP "PedEventsMod" framedelta 4.0 loopA 1 lockX 0 lockY 0 lockF 0 time -1  // versionB
        end



        model.Destroy(26)
        model.Destroy(1463)
        model.Destroy(367)

        progress = 0

        timera = 0
        progress = 0

        repeat
        wait 0
        if
            056D:   actor tour_man defined
        then

            080E: get_actor tour_man ped_event_to 1@
            if or
                0118:   actor tour_man dead
                not locate_char_distance_to_char $player_actor char tour_man radius 150.0
                not $ACTIVE_INTERIOR == 0
                051A:   actor tour_man damaged_by_actor $PLAYER_ACTOR
                not is_char_script_controlled tour_man
                1@ == 49
                1@ == 9
            then
                break
            end
            
            if
                056D:   actor tour_man_2 defined
            then
                080E: get_actor tour_man_2 ped_event_to 1@
                if or
                    0118:   actor tour_man_2 dead
                    not locate_char_distance_to_char $player_actor char tour_man_2 radius 150.0
                    051A:   actor tour_man_2 damaged_by_actor $PLAYER_ACTOR
                    not is_char_script_controlled tour_man_2
                    1@ == 49
                    1@ == 9
                then
                    break
                end
            end


            if
                select == 1
            then
                if and
                    0EE4: locate_char_distance_to_char $PLAYER_ACTOR char tour_man radius 15.0
                    progress == 0
                then
                    if or
                        timera > 15000
                        0EE4: locate_char_distance_to_char $PLAYER_ACTOR char tour_man radius 3.0
                    then
                        0812: AS_actor tour_man perform_animation "tour_stay" IFP "PedEventsMod" framedelta 2.0 loopA 0 lockX 0 lockY 0 lockF 0 time -1  // versionB
                        timerb = 0
                        progress = 1
                    end
                else
                    timera = 0
                end
            
                if
                    progress == 1
                then
                    if
                        0611:   actor tour_man performing_animation "tour_stay"
                    then
                        0613: 1@ = actor tour_man animation "tour_stay" time
                        if
                            1@ > 0.7
                        then
                            break
                        end
                    else
                        if
                            timerb > 5000
                        then
                            break
                        end
                    end
                end
            end
            
            if
                select == 2
            then
                if and
                    progress == 0
                    0EE4: locate_char_distance_to_char $PLAYER_ACTOR char tour_man radius 15.0
                    0611:   actor tour_man performing_animation "tour_map"
                then
                    0613: 1@ = actor tour_man animation "tour_map" time
                    if
                        1@ > 0.95
                    then
                        TIMERA = 0
                        progress = 1
                        gosub @go_away
                        0209: time_out = random_int_in_ranges 20000 40000
                    end
                end
                
                if and
                    0EE4: locate_char_distance_to_char $PLAYER_ACTOR char tour_man radius 20.0
                    progress == 1
                then
                    0EFF: get_char_simplest_active_task tour_man id_to 1@ pointer_to 3@
                    if or
                        1@ == 203
                        001D:   TIMERA > time_out  // (int)
                    then
                        0812: AS_actor tour_man perform_animation "tour_map" IFP "PedEventsMod" framedelta 2.0 loopA 1 lockX 1 lockY 1 lockF 0 time -1  // versionB
                        progress = 0
                    end
                end
            end
            
            if
                select == 3
            then
                if and
                    progress == 0
                    0EE4: locate_char_distance_to_char $PLAYER_ACTOR char tour_man radius 15.0
                    0611:   actor tour_man performing_animation "tour_cum"
                then
                    0613: 1@ = actor tour_man animation "tour_cum" time
                    if
                        1@ > 0.95
                    then
                        TIMERA = 0
                        progress = 1
                        gosub @go_away
                        0209: time_out = random_int_in_ranges 10000 30000
                    end
                end

                if and
                    0EE4: locate_char_distance_to_char $PLAYER_ACTOR char tour_man radius 20.0
                    progress == 1
                then
                    0EFF: get_char_simplest_active_task tour_man id_to 1@ pointer_to 3@
                    if or
                        1@ == 203
                        001D:   TIMERA > time_out  // (int)
                    then
                        0812: AS_actor tour_man perform_animation "tour_cum" IFP "PedEventsMod" framedelta 2.0 loopA 1 lockX 1 lockY 1 lockF 0 time -1  // versionB
                        progress = 0
                    end
                end
            end
            
            if
                select == 4
            then
                04C4: store_coords_to 1@ 2@ 3@ from_actor tour_man with_offset 0.0 0.0 0.0
                0EB2: get_offset_from_camera_in_world_coords 0.0 0.0 0.0 store_to 4@ 5@ 6@
                050A: 1@ = distance_between_XYZ 1@ 2@ 3@ and_XYZ 4@ 5@ 6@
                1@ /= 50.0
                2@ = 0.7
                0063: 2@ -= 1@  // (float)
                    if
                        2@ < 0.0
                    then
                        2@ = 0.0
                    end
                0ABC: set_audio_stream music volume 2@
            end
            
            if or
                select == 4
                select == 5
            then
                0E40: get_current_hour 1@
                if and
                    1@ >= 6
                    1@ < 21
                then
                    break
                end
            end
            

        else
            break
        end
        
        until not player.Defined(0)
            if
                select == 4
            then
                0650: destroy_particle fire_fx
                0AAE: remove_audio_stream music
            end
            if
                select == 5
            then
                0650: destroy_particle fire_fx
            end
            if 056D:   actor tour_man defined
            then 01C2: remove_references_to_actor tour_man // Like turning an actor into a random pedestrian
            end
            if 056D:   actor tour_man_2 defined
            then 01C2: remove_references_to_actor tour_man_2 // Like turning an actor into a random pedestrian
            end
            if 03CA:   object obj_1 exists
            then 01C4: remove_references_to_object obj_1 // This object will now disappear when the player looks away
            end
            if 03CA:   object obj_2 exists
            then 01C4: remove_references_to_object obj_2 // This object will now disappear when the player looks away
            end
        04EF: release_animation "PedEventsMod"

        repeat
        wait 0
        until not locate_char_distance_to_coordinates $PLAYER_ACTOR pos coords_x coords_y coords_z radius 100.0
        
        wait 60000

0A93: terminate_this_custom_script

:go_away
0208: 1@ = random_float_in_ranges 20.0 50.0
0208: 2@ = random_float_in_ranges 20.0 50.0
0209: 3@ = random_int_in_ranges 1 3
if 3@ == 1
then 1@ *= -1.0
end
04C4: store_coords_to 1@ 2@ 3@ from_actor tour_man with_offset 1@ 2@ 100.0
02CE: 3@ = ground_z_at 1@ 2@ 3@
0172: 4@ = actor tour_man Z_angle
07CD: AS_actor tour_man walk_to 1@ 2@ 3@ stop_with_angle 4@ within_radius 2.0
return